#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>

using namespace std;

long long subArrayRanges(vector<int>& nums) {
    int n = nums.size();
    long long res = 0;
    for (int i = 0; i < n; i++)
    {
        int nmin = INT_MAX, nmax = INT_MIN;
        for (int j = i; j < n; j++)
        {
            nmin = min(nmin, nums[j]);
            nmax = max(nmax, nums[j]);
            res += nmax - nmin;
        }
    }
    return res;
}

int main()
{
    return 0;
}